package com.tyun.modules.sys.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tyun.modules.sys.entity.SysUser;
import com.tyun.modules.sys.mapper.SysUserMapper;
import com.tyun.modules.sys.service.ISysUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * @author taocongcong
 * @create 2017-12-15 13:46
 */
@Service("sysUserService")
@CacheConfig(cacheNames = "sysUser")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper,SysUser> implements ISysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<String> queryMenuIdByUserId(String userId) {
        return sysUserMapper.queryMenuIdByUserId(userId);
    }

    @Override
    public Set<String> queryUserMenuPermsList(String userId) {
        List<String> permsList = sysUserMapper.queryUserMenuPermsList(userId);
        Set<String> permsSet = new HashSet<>();
        for (String perm : permsList) {
            if (StringUtils.isNotEmpty(perm)){
                permsSet.addAll(Arrays.asList(perm.trim().split(",")));
            }
        }
        return permsSet;
    }

    @Override
    public List<String> queryMenuIdByRoleId(String roleId) {
        return sysUserMapper.queryMenuIdByRoleId(roleId);
    }
}
